var e = getApp(),
  n = require("../../utils/core.js");

Page({
  data: {
    shop_logo: "",
    shop_name: "",
    imgUrls: [
      '../../static/images/bgm.jpg',
      '../../static/images/bgm.jpg',
    ],
    exportanimation:''
  },
  onLoad: function(e) {
    var o = this;
    n.get("wxAppSetting", {}, function(e) {
      var n = e.sysset;
      o.setData({
        shop_logo: n.shoplogo,
        shop_name: n.shopname
      });
    });
  },
  onReady: function() {},
  onShow: function () {
    var query = wx.createSelectorQuery();
    var that = this;
    var height;
    var hteight1;
    var height2;
    var distance = -1;
    wx.getSystemInfo({
      success: function (res) {
        hteight1 = res.windowHeight;
      },
    })
    query.select('.every').boundingClientRect(function (rect) {
      height = rect.height - hteight1;
      setTimeout(function(){
        interv = setInterval(function () {
          distance -= 1;
          if (-distance > height) {
            distance = -1;
            var exportanimation = wx.createAnimation({
              duration: 0,
              timingFunction: 'step-start',
              delay: 0
            })
            exportanimation.translateY(distance).step();
            that.setData({
              exportanimation: exportanimation.export()
            })
          } else {
            var exportanimation = wx.createAnimation({
              duration: 50,
              timingFunction: 'linear',
              delay: 0
            })
            exportanimation.translateY(distance).step();
            that.setData({
              exportanimation: exportanimation.export()
            })
          }
        }, 50)
      },500)
    }).exec();
  },
  destroy:function(){
    clearInterval(interv);
    var exportanimation = wx.createAnimation({
      duration: 200,
      timingFunction: 'step-end',
    })
    exportanimation.translateY(-1).step();
    this.setData({
      exportanimation: exportanimation.export()
    })
  },
  onHide: function() {
    this.destroy();
  },
  onUnload: function() {
    this.destroy();
  },
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function() {},
  bindGetUserInfo: function(o) {
    wx.showLoading({
      title: "加载中"
    }), wx.login({
      success: function(t) {
        n.post("wxapp/login", {
          code: t.code
        }, function(t) {
          t.error ? n.alert("获取用户登录态失败:" + t.message) : n.get("wxapp/auth", {
            data: o.detail.encryptedData,
            iv: o.detail.iv,
            sessionKey: t.session_key
          }, function(n) {
            1 == n.isblack && wx.showModal({
                title: "无法访问",
                content: "您在商城的黑名单中，无权访问！",
                success: function(n) {
                  n.confirm && e.close(), n.cancel && e.close();
                }
              }), o.detail.userInfo.openid = n.openId, o.detail.userInfo.id = n.id, o.detail.userInfo.uniacid = n.uniacid,
              e.setCache("userinfo", o.detail.userInfo), e.setCache("userinfo_openid", o.detail.userInfo.openid),
              e.setCache("userinfo_id", n.id), e.getSet(), wx.navigateBack({
                changed: !0
              });
          });
        });
      },
      fail: function() {
        n.alert("获取用户信息失败!");
      },
      complete: function() {
        wx.hideLoading();
      }
    });
  },
  navigateBack: function() {
    wx.navigateBack({
      changed: !0
    });
  },
  close: function() {
    wx.navigateBack({
      delta: 0
    });
  }
});